<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./node_modules/axios/dist/axios.min.js"></script>
</head>

<body>
    <ul class="list">
        <li></li>
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');

        btns[0].onclick = async function() {
            // axios("http://api.zhibao.com/movies").then(val => {
            //     // console.log(val.data);
            //     let str = val.data.map(item => `<li>${item.name}</li>`).join('');

            //     ul.innerHTML = str;
            // })
            let {
                data
            } = await axios("http://api.zhibao.com/movies");
            // console.log(val.data);
            let str = data.map(item => `<li>${item.name}</li>`).join('');
            ul.innerHTML = str;
        }

        btns[1].onclick = async function() {
            let data = await axios({
                url: "http://api.zhibao.com/movies",
                method: "post",
                data: {
                    name: "消失的她",
                    director: "陈思诚",
                    star: "朱一龙、倪妮"
                }
            })
            console.log(data.status);
        }

        btns[2].onclick = async function() {
            let data = await axios({
                url: "http://api.zhibao.com/movies/11",
                method: "put",
                data: {
                    name: "忠犬八公"
                }
            })
            console.log(data);
        }

        btns[3].onclick = async function() {
            let data = await axios({
                url: "http://api.zhibao.com/movies/10",
                method: "patch",
                data: {
                    name: "唐人街探案"
                }
            })
            console.log(data);
        }

        btns[4].onclick = async function() {
            let data = await axios({
                url: "http://api.zhibao.com/movies/11",
                method: "delete",
            })
            console.log(data);
        }
    </script>
</body>

</html>